﻿
namespace Ultima.Xna.Extensions
{
    public static class StringExtensions
    {
        /// <summary>
        /// Counts the number of times a character exists in a string
        /// </summary>
        /// <param name="str">The string to check</param>
        /// <param name="ch">The character to search for</param>
        public static int CountChar(this string str, char ch)
        {
            int count = 0;
            int index = -1;

            while ((index = str.IndexOf(ch, index + 1)) != -1)
            {
                count++;
            }

            return count;
        }
    }
}
